<?php

class Member_controller extends CI_Controller {
    
    function Member_controller() {
        parent::__construct();
        
        $this->load->model('Member_model');
    }
    
    public function index() {
        $this->load->library('session');
        $data['lang'] = $this->session->userdata('lang');
        $data['member_id'] = $this->session->userdata('member_id');
        $data['firstname'] = $this->session->userdata('firstname');
        $this->load->model('Panel_model');
        $data['panel'] = $this->Panel_model->admin_menus_list();
        foreach ($data['panel'] as $key => $option) {
            $data['panel'][$key]['option'] = $this->Panel_model->admin_options_list($option['admin_panel_id']);
        }
        
        $data['route'] = 'users';
        $data['members'] = $this->Member_model->members_list();
        
        $this->load->view('layout/admin', $data);
    }
    
    public function set() {
        $data = $this->input->post();
        
        $this->Member_model->member_set($data['firstname'], $data['lastname'], $data['username'], $data['email'], $data['password']);
        
        $this->index();
    }
    
    public function delete($member_id) {
        $this->Member_model->member_delete($member_id);
        
        $this->index();
    }
    
    public function update($member_id) {
        $data = $this->input->post();
        
        $this->Member_model->member_update($member_id, $data['firstname'], $data['lastname'], $data['username'], $data['email'], $data['password']);
        
        $this->index();
    }    
    
}

?>